package com.sunwayhorizo.health.hl7.rim;

import com.sunwayhorizo.health.hl7.common.*;
import com.sunwayhorizo.health.hl7.datatypes.*;
import com.sunwayhorizo.health.hl7.factories.*;
import com.sunwayhorizo.health.hl7.persistent.*;
import java.io.*;
import javax.persistence.*;
import static com.sunwayhorizo.health.hl7.vocabulary.RoleCdSetCode.*;

@Entity
@DiscriminatorValue("EMP")
@Inheritance
public class Employee extends Role implements Serializable
{
    protected static final long serialVersionUID = 1L;
    /*
     * public ED hazardExposureText; public CE jobClassCode; public CE jobCode;
     * public SC jobTitleName; public ED protectiveEquipmentText; public MO
     * salaryQuantity; public CE salaryTypeCode;
     */


    public Employee() throws Hl7Exception
    {
    }


    /**
     * 雇主或雇员的工作名称 例如，副总统，高级技术分析家
     * 
     * @author jinzw
     * @data 2010-11-12
     */
    public Employee(ReferenceModifier referencemodifier)
    {

        super(referencemodifier);
    }


    public void setHazardExposureText(ED hazardExposureText)
    {
        RimCoreEds ed = this.getRimCoreEdsEmHazardExposureEdId();
        converRimCoreEds(ed,hazardExposureText);
        this.setRimCoreEdsEmHazardExposureEdId(ed);
    }


    public ED getHazardExposureText() throws Hl7Exception
    {
        RimCoreEds ed = this.getRimCoreEdsEmHazardExposureEdId();
        if (null == ed)
        {
            return null;
        }
        return DataTypeUtil.getED(new String(ed.getEdClob()), ed.getEdBlob());
    }


    public void setJobClassCode(CE ce)
    {
        if (null != ce && ce.codeSystemEnName() != null && ce.codeName() != null)
        {
            setRimCoreRoleCdSets(ce, JOBCLASSCODE);
        }
        else
        {
            this.setEmJobClassCodeEtsId(ce.code().toString());
        }
    }


    public CE getJobClassCode() throws Hl7Exception
    {
        if (this.getEmJobClassCodeEtsId().equals(JOBCLASSCODE.toString()))
        {
            for (RimCoreRoleCdSets roleCdSets : this.getRoleCdSetsList())
            {
                if (this.getEmJobClassCodeEtsId().equals(roleCdSets.getAttributeTypeCode()))
                {
                    return DataTypeUtil.getCE(roleCdSets);
                }
            }
        }
        else
            return DataTypeUtil.getCE(this.getEmJobClassCodeEtsId());
        return null;
    }


    public void setJobCode(CE ce)
    {
        if (null != ce && ce.codeSystemEnName() != null && ce.codeName() != null)
        {
            this.setRimCoreRoleCdSets(ce, JOBCODE);
        }
        else
        {
            this.setEmJobCodeEtsId(ce.code().toString());
        }
    }


    /**
     * 员工的职务（包括会计师，程序员分析师，病人护理助理，工作人员护士）
     * 
     * @return CE
     * @throws Hl7Exception
     */
    public CE getJobCode() throws Hl7Exception
    {
        if (null !=this.getEmJobCodeEtsId() && this.getEmJobCodeEtsId().equals(JOBCODE.toString()))
        {
            for (RimCoreRoleCdSets roleCdSets : this.getRoleCdSetsList())
            {
                if (this.getEmJobCodeEtsId().equals(roleCdSets.getAttributeTypeCode()))
                {
                    return DataTypeUtil.getCE(roleCdSets);
                }
            }
        }
        else
            return DataTypeUtil.getCE(this.getEmJobCodeEtsId());
        return null;
    }


    public void setJobTitleName(CE jobTitleName)
    {
        if (null != jobTitleName && jobTitleName.codeSystemEnName() != null && jobTitleName.codeName() != null)
        {
            this.setRimCoreRoleCdSets(jobTitleName, JOBTITLECODE);
        }
        else
        {
            this.setEmJobTitleCodeEtsId(jobTitleName.code().toString());
        }
    }


    /**
     * 得到员工职称
     * 
     * @return CE
     * @throws Hl7Exception
     */
    public CE getJobTitleName() throws Hl7Exception
    {
        if (this.getEmJobTitleCodeEtsId().equals(JOBTITLECODE.toString()))
        {
            for (RimCoreRoleCdSets roleCdSets : this.getRoleCdSetsList())
            {
                if (this.getEmJobTitleCodeEtsId().equals(roleCdSets.getAttributeTypeCode()))
                {
                    return DataTypeUtil.getCE(roleCdSets);
                }
            }
        }
        else
            return DataTypeUtil.getCE(this.getEmJobTitleCodeEtsId());
        return null;
    }


    /**
     * 设置ED类型的数据到RimCoreEds，主要设置为防护类型，如电子签名等
     * 
     * @param protectiveEquipmentText
     */
    public void setProtectiveEquipmentText(ED protectiveEquipmentText)
    {

        RimCoreEds ed = this.getRimCoreEdsEmProtectiveEqpEdId();
        converRimCoreEds(ed,protectiveEquipmentText);
        this.setRimCoreEdsEmProtectiveEqpEdId(ed);
    }
    
    /**
     * 得到ProtectiveEquipmentText并封装成二进制数据
     * 
     * @return ED
     * @throws Hl7Exception
     */
    public ED getProtectiveEquipmentText() throws Hl7Exception
    {
        RimCoreEds ed = this.getRimCoreEdsEmProtectiveEqpEdId();
        if (null == ed)
        {
            return null;
        }
        return DataTypeUtil.getED(new String(ed.getEdClob()), ed.getEdBlob());
    }


    public void setSalaryQuantity(MO salaryQuantity)
    {
        this.setEmSalaryQty(salaryQuantity.value().doubleValue());
        this.setEmSalaryQtyTxt(salaryQuantity.literal().toString());
        this.setEmSalaryCurrencyCode(salaryQuantity.currency().code().toString());
    }


    public MO getSalaryQuantity() throws Hl7Exception
    {
        return DataTypeUtil.getMO(this.getEmSalaryQty(), this.getEmSalaryCurrencyCode());
    }


    public void setSalaryTypeCode(CE ce)
    {
        if (null != ce && ce.codeSystemEnName() != null && ce.codeName() != null)
        {
            this.setRimCoreRoleCdSets(ce, SALARYTYPECODE);
        }
        else
        {
            this.setEmSalaryTypeCodeEtsId(ce.code().toString());
        }
    }


    public CE getSalaryTypeCode() throws Hl7Exception
    {
        if (this.getEmSalaryTypeCodeEtsId().equals(SALARYTYPECODE.toString()))
        {
            for (RimCoreRoleCdSets roleCdSets : this.getRoleCdSetsList())
            {
                if (this.getEmSalaryTypeCodeEtsId().equals(roleCdSets.getAttributeTypeCode()))
                {
                    return DataTypeUtil.getCE(roleCdSets);
                }
            }
        }
        else
            return DataTypeUtil.getCE(this.getEmSalaryTypeCodeEtsId());
        return null;
    }

    // Employee
    @Column(name = "EM_JOB_CLASS_CODE_ETS_ID")
    protected String emJobClassCodeEtsId = JOBCLASSCODE.toString();
    @Column(name = "EM_JOB_CODE_ETS_ID")
    protected String emJobCodeEtsId = JOBCODE.toString();
    @Column(name = "EM_JOB_TITLE_CODE_ETS_ID")
    protected String emJobTitleCodeEtsId = JOBTITLECODE.toString();
    @Column(name = "EM_JOB_TITLE_NAME")
    protected String emJobTitleName;
    @Column(name = "EM_SALARY_CURRENCY_CODE")
    protected String emSalaryCurrencyCode;
    @Column(name = "EM_SALARY_QTY")
    protected Double emSalaryQty;
    @Column(name = "EM_SALARY_QTY_TXT")
    protected String emSalaryQtyTxt;
    @Column(name = "EM_SALARY_TYPE_CODE_ETS_ID")
    protected String emSalaryTypeCodeEtsId = SALARYTYPECODE.toString();


    protected String getEmJobClassCodeEtsId()
    {
        return emJobClassCodeEtsId;
    }


    protected void setEmJobClassCodeEtsId(String emJobClassCodeEtsId)
    {
        this.emJobClassCodeEtsId = emJobClassCodeEtsId;
    }


    protected String getEmJobCodeEtsId()
    {
        return emJobCodeEtsId;
    }


    protected void setEmJobCodeEtsId(String emJobCodeEtsId)
    {
        this.emJobCodeEtsId = emJobCodeEtsId;
    }


    protected String getEmJobTitleCodeEtsId()
    {
        return emJobTitleCodeEtsId;
    }


    protected void setEmJobTitleCodeEtsId(String emJobTitleCodeEtsId)
    {
        this.emJobTitleCodeEtsId = emJobTitleCodeEtsId;
    }


    @SuppressWarnings("unused")
    protected String getEmJobTitleName()
    {
        return emJobTitleName;
    }


    @SuppressWarnings("unused")
    protected void setEmJobTitleName(String emJobTitleName)
    {
        this.emJobTitleName = emJobTitleName;
    }


    protected String getEmSalaryCurrencyCode()
    {
        return emSalaryCurrencyCode;
    }


    protected void setEmSalaryCurrencyCode(String emSalaryCurrencyCode)
    {
        this.emSalaryCurrencyCode = emSalaryCurrencyCode;
    }


    protected Double getEmSalaryQty()
    {
        return emSalaryQty;
    }


    protected void setEmSalaryQty(Double emSalaryQty)
    {
        this.emSalaryQty = emSalaryQty;
    }


    @SuppressWarnings("unused")
    protected String getEmSalaryQtyTxt()
    {
        return emSalaryQtyTxt;
    }


    protected void setEmSalaryQtyTxt(String emSalaryQtyTxt)
    {
        this.emSalaryQtyTxt = emSalaryQtyTxt;
    }


    protected String getEmSalaryTypeCodeEtsId()
    {
        return emSalaryTypeCodeEtsId;
    }


    protected void setEmSalaryTypeCodeEtsId(String emSalaryTypeCodeEtsId)
    {
        this.emSalaryTypeCodeEtsId = emSalaryTypeCodeEtsId;
    }

}
